package com.nanuminc.market;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TabHost;
import android.widget.Toast;

import com.nanuminc.market.mapsearch.MyMapSearch;
import com.nanuminc.market.settings.SettingGroup;
import com.nanuminc.market.today.TodayMain;
import com.nanuminc.market.today.TodayMain_ngoc;
import com.nanuminc.market.today.type.TodayListAB;

public class MarketMain extends TabActivity {
	TabHost mTabHost = null;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.market_main);
	    
	    //탭 설정
	    mTabHost = getTabHost();
        mTabHost.addTab(mTabHost.newTabSpec("ngoc") // This tab will be display first and active first
        		//.setIndicator("나누미").setContent(R.id.tabview03)); 
        		.setIndicator("메인").setContent( new Intent(this,TodayMain_ngoc.class)));
        mTabHost.addTab(mTabHost.newTabSpec("tab_today")
        		.setIndicator("오늘광고").setContent( new Intent(this,TodayMain.class)));
        mTabHost.addTab(mTabHost.newTabSpec("tab_mapsearch")
        		.setIndicator("내주변").setContent( new Intent(this,MyMapSearch.class)));
        mTabHost.addTab(mTabHost.newTabSpec("SettingGroup")
        		.setIndicator("설정").setContent( new Intent(this,SettingGroup.class)));
       // mTabHost.addTab(mTabHost.newTabSpec("Test")
       //		.setIndicator("Test").setContent( R.id.tabview03));
        mTabHost.setCurrentTab(0);   //Tab 위치 설정   	
	}
	
	/**
	 * 탭 추가.
	 * 
	 * @param id 탭아이디(String)
	 * @param resource 탭버튼 리소스
	 * @param activity 탭 컨텐트 액티비티
	 */
/*	private void addTab(String id, int resource, Class<?> activity)
	{
		//View tabButton = getLayoutInflater().inflate(R.layout.settings, null);
		//tabButton.setBackgroundResource(resource);
		
		Intent intent = new Intent(this, activity);
		
		TabSpec spec = mTabHost.newTabSpec(id);
		//spec.setIndicator(tabButton);
		spec.setIndicator("설정");
		spec.setContent(intent);
		
		mTabHost.addTab(spec);
	}*/
	
	@Override
	
	
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {  //종료하기
		try {

	        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
	        	AlertDialog.Builder bld = new AlertDialog.Builder(MarketMain.this);
					bld.setTitle("나눔장터");
					bld.setMessage("종료 하시겠습니까?");
					bld.setPositiveButton("예", new DialogInterface.OnClickListener(){
					    public void onClick(DialogInterface dialog, int whichButton){
							Toast.makeText(MarketMain.this,"나눔장터를 종료합니다.", 0).show();
				        	System.exit(0);		
					    }
					});
					bld.setNegativeButton("아니오", new DialogInterface.OnClickListener(){
					    public void onClick(DialogInterface dialog, int whichButton){
						Toast.makeText(MarketMain.this,"취소 되었습니다.", 0).show();
					    }
					});
					bld.show();
		        	return true;
	        }
	        return super.onKeyDown(keyCode, event);

		} catch (Exception ex) {
			ex.printStackTrace();
			return super.onKeyDown(keyCode, event);
		}
	}	
}
